import React, { useState } from "react";
import { Outlet, Link, useLocation, useNavigate } from "react-router-dom";
import "./index.css";
import {
  MenuFoldOutlined,
  MenuUnfoldOutlined,
  // UploadOutlined,
  // UserOutlined,
  // VideoCameraOutlined,
  DownOutlined,
  HomeOutlined,
  UserOutlined,
  ReadOutlined,
} from "@ant-design/icons";
import { Button, Layout, Menu, theme, Dropdown, Space, Image } from "antd";
const { Header, Sider, Content, Footer } = Layout;

const Home = () => {
  const navigate = useNavigate();
  const [collapsed, setCollapsed] = useState(false);
  const {
    token: { colorBgContainer, borderRadiusLG },
  } = theme.useToken();
  const items = [
    {
      label: "退出",
      key: "1",
    },
  ];
  const menus = [
    {
      key: "/",
      icon: <HomeOutlined />,
      label: "首页",
    },
    {
      key: "/user",
      icon: <UserOutlined />,
      label: "用户管理",
      // children: [
      //   { key: "5", label: "Option 5" },
      //   { key: "6", label: "Option 6" },
      // ],
    },
    {
      key: "/blog",
      icon: <ReadOutlined />,
      label: "博客管理",
    },
  ];
  // 退出
  const onClick = ({ key }) => {
    // userLogout();
    navigate("/login");
  };
  const changeMenu = ({ item, key, keyPath, domEvent }) => {
    navigate(key);
  };
  return (
    <Layout style={{ height: "100vh" }}>
      <Sider trigger={null} collapsible collapsed={collapsed}>
        <div className="demo-logo-vertical" />
        <Menu
          theme="dark"
          mode="vertical"
          defaultSelectedKeys={["/"]}
          items={menus}
          onClick={changeMenu}
        />
      </Sider>
      <Layout>
        <Header
          style={{
            width: "100%",
            padding: 0,
            background: colorBgContainer,
            display: "flex",
            justifyContent: "space-between",
          }}
        >
          <Button
            type="text"
            icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
            onClick={() => setCollapsed(!collapsed)}
            style={{
              fontSize: "16px",
              width: 64,
              height: 64,
            }}
          />
          <div className="user-info">
            <Dropdown menu={{ items, onClick }}>
              <a onClick={(e) => e.preventDefault()}>
                <Space>
                  {/* {userInfo?.name} */}
                  <DownOutlined />
                </Space>
              </a>
            </Dropdown>
          </div>
        </Header>
        <Content
          style={{
            margin: "24px 16px",
            padding: 24,
            minHeight: 280,
            background: colorBgContainer,
            borderRadius: borderRadiusLG,
          }}
        >
          <Outlet></Outlet>
        </Content>
        <Footer
          style={{
            textAlign: "center",
          }}
        >
          xx技术 ©{new Date().getFullYear()} Created by xx技术
        </Footer>
      </Layout>
    </Layout>
  );
};
export default Home;
